/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd.            */
/*                                                                 */
/*  NAME      = t__sqlserver_bigint_add.c                          */
/*  NOTE      =                                                    */
/*  DATE      = 2014/11/25 by geyh                                 */
/*******************************************************************/

#include <stdio.h>
#include <string.h>
#include <CUnit/Basic.h>

#include <frmem.h>

#include <sqlserver/config.h>
#include <sqlserver/sqlserver_base_type.h>

#define MSSQL_16BYTE_MAX_LEN              78

extern void __sqlserver_bigint_add(char *p_addend, char *p_augend, char *p_result);

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    char *p_addend = (char *) "0";
    char *p_augend = (char *) "0";
    char *p_result = NULL;

    p_result = (char *) frmalloc(MSSQL_16BYTE_MAX_LEN + 1);
    memset(p_result, 0x00, MSSQL_16BYTE_MAX_LEN + 1);

    __sqlserver_bigint_add(p_addend, p_augend, p_result);

    CU_ASSERT_STRING_EQUAL(p_result, "0");
    frfree(p_result);

    return;
}

static void __case2(void)
{
    char *p_addend = (char *) "0";
    char *p_augend = (char *) "546";
    char *p_result = NULL;

    p_result = (char *) frmalloc(MSSQL_16BYTE_MAX_LEN + 1);

    __sqlserver_bigint_add(p_addend, p_augend, p_result);

    CU_ASSERT_STRING_EQUAL(p_result, "546");
    frfree(p_result);

    return;
}

static void __case3(void)
{
    char *p_addend = (char *) "90496544199165";
    char *p_augend = (char *) "0";
    char *p_result = NULL;

    p_result = (char *) frmalloc(MSSQL_16BYTE_MAX_LEN + 1);

    __sqlserver_bigint_add(p_addend, p_augend, p_result);

    CU_ASSERT_STRING_EQUAL(p_result, "90496544199165");
    frfree(p_result);

    return;
}

static void __case4(void)
{
    char *p_addend = (char *) "90496544199165";
    char *p_augend = (char *) "546";
    char *p_result = NULL;

    p_result = (char *) frmalloc(MSSQL_16BYTE_MAX_LEN + 1);

    __sqlserver_bigint_add(p_addend, p_augend, p_result);

    CU_ASSERT_STRING_EQUAL(p_result, "90496544199711");
    frfree(p_result);

    return;
}

int add_suite__sqlserver_bigint_add(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __sqlserver_bigint_add()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    //增加测试用例
    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL ||
        CU_add_test(pSuite, "case4", __case4) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
